#include "wxPaintView.h"

wxPaintView::wxPaintView(wxWindow *parent,
                         const wxPoints *points) : wxPanel(parent,
                                                        wxID_ANY,
                                                        wxPoint(0,0),
                                                        wxSize(200, 300))
{
    shouldIDraw = false;
    this->points = points;

    Connect(wxEVT_PAINT, (wxObjectEventFunction) &wxPaintView::OnPaint);
    Connect(wxEVT_SIZE, (wxObjectEventFunction) &wxPaintView::OnResize);
}

wxPaintView::~wxPaintView()
{
    shouldIDraw = false;
}

void wxPaintView::SetDrawFlag(bool shouldIDraw)
{
    this->shouldIDraw = shouldIDraw;
    Refresh();
}

void wxPaintView::OnResize(wxSizeEvent& evt)
{
    Refresh();
}

void wxPaintView::OnPaint(wxPaintEvent& evt)
{
    if(shouldIDraw)
    {
        wxPaintDC dc(this);

        wxRect rect = GetClientRect();

        DCUtils::draw(&dc, points, &rect);
    }
}
